package com.ftg.learn.bus.user.controller;

import com.ftg.learn.bus.user.pojo.user;
import com.ftg.learn.bus.user.service.user_service;
import com.ftg.learn.bus.util.ResultType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController("/use")
@Api(value = "用户表",tags = "用户表")
@CrossOrigin
public class user_controller {
    @Autowired
    user_service us;

    @GetMapping("/user_query")
    @ApiOperation(value = "查询全部用户信息 ps:不包括密码")
    public ResultType<user> query(int page,int limit,String user_id,String name){
        return us.query(page, limit, "", "");
    }

    @PostMapping("/user_add")
    @ApiOperation(value = "注册")
    public int add(@RequestBody user s){
        return us.add(s);
    }

    @PostMapping("/user_login/{user_id}&{password}")
    @ApiOperation(value = "登录")
    public ResultType<Map<String, Object>> login(@ApiParam("用户名") @PathVariable String user_id, @ApiParam("密码") @PathVariable String password){
        return us.login(user_id,password);
    }

    @PutMapping("/user_queryone/{user_id}")
    @ApiOperation(value = "根据用户名查询某个用户信息")
    public user queryone(@ApiParam("user_id") @PathVariable String user_id){
        return us.queryone(user_id);
    }

    @PostMapping("/user_update")
    @ApiOperation(value = "修改个人信息")
    public int update(@RequestBody user s){
        return us.update(s);
    }

    @DeleteMapping("/user_delete/{user_id}")
    @ApiOperation("删除/销户")
    public int delete(@ApiParam("user_id") @PathVariable String user_id){
        return us.delete(user_id);
    }

    @DeleteMapping("/user_deletes/{user_ids}")
    @ApiOperation("多条删除/销户")
    public int delete(@ApiParam("用户名(多条)") @PathVariable List<String> user_ids){
        return us.deletes(user_ids);
    }
}
